package com.linxz.framework.base.adapter;

import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;

/**
 * @author Linxz
 * 创建日期：2019年02月21日 13:57
 * version：1.0.0
 * 描述：
 */
public class ViewHolder {
    private View convertView;
    private SparseArray<View> views;

    public ViewHolder(View convertView) {
        this.convertView = convertView;
        views = new SparseArray<View>();
    }

    public <T extends View> T getView(int viewId) {
        View view = views.get(viewId);
        if (view == null) {
            view = convertView.findViewById(viewId);
            views.put(viewId, view);
        }
        return (T) view;
    }

    public void setText(int resId, String text) {
        ((TextView) getView(resId)).setText(text);
    }
}
